package com.md.controller;

import com.md.entity.Student;
import com.md.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService ;

    @GetMapping
    public List<Student> getStudents() {
        return studentService.getStudents();
    }

    @GetMapping(params = "studentName")
    public List<Student> getStudentByName(String studentName) {
        return studentService.getStudentByName(studentName);
    }

    @GetMapping("{id}")
    public Student getStudentById(@PathVariable String id) {
        return studentService.getStudentById(Integer.parseInt(id));
    }

    @DeleteMapping("{id}")
    public int DelStudentById(@PathVariable String id) {
        return studentService.DelStudentById(Integer.parseInt(id));
    }

    @PostMapping
    public int insertStudent(@RequestBody Student student) {
        return studentService.insertStudent(student);
    }

    @PutMapping
    public int updateStudent(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }
}
